﻿using MediatR;
using Return.Enum;
using SlaughterItem.Common.Infrastructures.Interfaces;
using THE_WIND_RISES.Common.Domans.BasicInformation.warehouses;
using THE_WIND_RISES.Common.Dtos;

namespace Enterprise_Set.API.Application.Commands.Week3.WHAllot_CRUD
{
    /// <summary>
    /// 获取所有仓库
    /// </summary>
    public class GetWHAllotHander : IRequestHandler<WHAllotCommand, Result>
    {
        private readonly IBaseRepository<Warehouse> WarehouseRepository;

        public GetWHAllotHander(IBaseRepository<Warehouse> warehouseRepository)
        {
            WarehouseRepository = warehouseRepository;
        }

        public async Task<Result> Handle(WHAllotCommand request, CancellationToken cancellationToken)
        {
            var result=new Result() { Code=(int)CommonErrorCodes.Search};
            var sql = "select * from Warehouse;";
            var WarehouseData = WarehouseRepository.GetAll(sql);
            if (WarehouseData != null)
            {
                result.Code = (int)CommonErrorCodes.Success;
                result.Data = WarehouseData;
                return result;
            }
            else
            { 
                return result;
            }
        }
    }
}
